package com.team2.shared;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;




public class Product implements java.io.Serializable, Parcelable
{
	private static final long serialVersionUID = -7115821217059693736L;
	private String id;
	private String title;
	private String description;
	private String imageLink;
	private String brand;
	private String condition;
	private String gtin; //Global Trade Item Number, the unique identifier
	private String link;
	private String price;
	private String modelNumber = "";
	private String provider; // A String indicating who provided the information. E.g. BestBuy, FutureShop
	private String inStoreAvailability = "";
	private String onlineAvailablility = "";
	private double similarity=0;
	private ArrayList<Store> stores = new ArrayList<Store>();

	public Product(String title, String description, String imageLink) {
		super();
		this.title = title;
		this.description = description;
		this.imageLink = imageLink;
	}
	public Product(){
	}
	public Product(ServerProduct serverProduct){
		super();
		this.brand = serverProduct.getBrand();
		this.condition = serverProduct.getCondition();
		this.id = serverProduct.getId();
		this.description = serverProduct.getDescription();
		this.imageLink = serverProduct.getImageLink();
		this.modelNumber = serverProduct.getModelNumber();
		this.title = serverProduct.getTitle();
		this.onlineAvailablility = serverProduct.getOnlineAvailablility();
		this.inStoreAvailability = serverProduct.getInStoreAvailability();
		this.price = serverProduct.getPrice();
		this.provider = serverProduct.getProvider();
		this.link = serverProduct.getLink();
		this.similarity = serverProduct.getSimilarity();
		ArrayList<Store> stores = new ArrayList<Store> ();
		for(ServerStore ss: serverProduct.getStores()){
			stores.add(new Store(ss));
		}
		this.stores = stores;
	}
	public static ArrayList<Product> fromServerProducts(List<ServerProduct> serverProducts){
		ArrayList<Product> products = new ArrayList<Product>();
		for(ServerProduct sp: serverProducts){
			products.add(new Product(sp));
		}
		return products;
		
	}
	
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getImageLink() {
		return imageLink;
	}
	public void setImageLink(String imageLink) {
		this.imageLink = imageLink;
	}
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public String getGtin() {
		return gtin;
	}
	public void setGtin(String gtin) {
		this.gtin = gtin;
	}
	public ArrayList<Store> getStores() {
		return stores;
	}
	public void setStores(ArrayList<Store> stores) {
		this.stores = stores;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}

	public String getPrice() {
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	public String getModelNumber() {
		return modelNumber;
	}
	public void setModelNumber(String modelNumber) {
		this.modelNumber = modelNumber;
	}
	public String getProvider() {
		return provider;
	}
	public void setProvider(String provider) {
		this.provider = provider;
	}
	public String getInStoreAvailability() {
		return inStoreAvailability;
	}
	public void setInStoreAvailability(String inStoreAvailability) {
		this.inStoreAvailability = inStoreAvailability;
	}
	public String getOnlineAvailablility() {
		return onlineAvailablility;
	}
	public void setOnlineAvailablility(String onlineAvailablility) {
		this.onlineAvailablility = onlineAvailablility;
	}
	
	@Override
	public int describeContents() {
		return 0;
	}
	@Override
	public void writeToParcel(Parcel out, int flags) {
		// TODO Auto-generated method stub
		//out.writeSerializable((Serializable) jsonArray); 
        out.writeString(id);
        out.writeString(title);
        out.writeString(description);
        out.writeString(imageLink);
        out.writeString(brand);
        out.writeString(condition);
        out.writeString(gtin);
        out.writeString(link);
        out.writeString(price);
        out.writeTypedList(stores);
        out.writeString(modelNumber);
        out.writeDouble(similarity);
        out.writeString(inStoreAvailability);
        out.writeString(onlineAvailablility);
	}
	
	public static final Parcelable.Creator<Product> CREATOR = new Parcelable.Creator<Product>() {
		public Product createFromParcel(Parcel in) {
			return new Product(in);
		}

		public Product[] newArray(int size) {
			return new Product[size];
		}
	};
	
	private Product(Parcel in) {
		
		this();
		id =in.readString();
		title =in.readString();
		description =in.readString();
		imageLink =in.readString();
		brand =in.readString();
		condition =in.readString();
		gtin =in.readString();
		link =in.readString();
		price = in.readString();
		in.readTypedList(stores, Store.CREATOR);
		modelNumber = in.readString();
		similarity = in.readDouble();
		inStoreAvailability = in.readString();
		onlineAvailablility=in.readString();
	}
	public double getSimilarity() {
		return similarity;
	}
	public void setSimilarity(double similarity) {
		this.similarity = similarity;
	}
	
	
}
